package com.kaoshi.myweb.webstruts.support;

import java.util.Locale;
import java.util.Map;

import org.apache.struts2.util.StrutsTypeConverter;

import com.kaoshi.myweb.webstruts.model.ConvertModel;

public class LocalConverter extends StrutsTypeConverter {
	@Override
	public Object convertFromString(Map context, String[] values, Class toClass) {
		System.out.println("calling convertFromString()");
		if (toClass == Locale.class) {
			String local = values[0];
			return new Locale(local.substring(0, 2), local.substring(3));
		}

		return null;
	}

	@Override
	public String convertToString(Map context, Object o) {
		System.out.println("calling convertToString()");
		Locale locale = (Locale) o;
		return locale.toString();
	}
}
